package edu.moravian.utilities;

import static org.junit.Assert.*;
import org.junit.Test;
/**
 *
 * This is a horrible test class. 
 * 
 * You can't reliably count on thread.sleep for timing measurements
 * 
 * A better way to do this would be with a built in timer or 
 * creating a new thread with executors?
 * 
 * @author Elliot
 */
public class TimerTest 
{
    public static double DELTA_TOL = .05;
    public static double FPS_TOL = .01;
    
    @Test
    public void testTick() throws InterruptedException
    {
        //sleep for a little so that the current
        //thread can catch up from work on other tests
        //so that our timings don't get even more skewed
        Thread.sleep(200);
        Timer t = new Timer();
        t.tick();
        try 
        {
            Thread.sleep(1000);
        } 
        catch (InterruptedException ex) 
        {
            //do nothing
            
        }
        t.tick();
        
       assertEquals(t.getDelta(), 1.0, DELTA_TOL);
       assertEquals(t.getFPS(), 1.0, FPS_TOL);
    }
    
    @Test 
    public void test60FPS()
    {
        Timer t = new Timer();
        t.tick();
        
        for(int i=0; i<60; i++)
        {
            try 
            {
                Thread.sleep(1000/60);
            } 
            catch (InterruptedException ex) 
            {
                //do nothing

            }
            t.tick();

           assertEquals((1.0/60.0), t.getDelta() , .05);
           assertEquals(60.0, t.getFPS(), 10.0);
        }
    }
}
